﻿using Sustainalytics.Utils;
using System;
using System.Configuration;
using System.IO;
using System.Reflection;

namespace Sustainalytics.ClientInterface.Service
{
    public class HostConfig
    {
        public static string GetHostUrl()
        {
            var url = ConfigurationManager.AppSettings["httpHostUrl"];
            var allowHttps = bool.Parse(ConfigurationManager.AppSettings["allowHttps"]);

            if (allowHttps)
            {
                var uriBuilder = new UriBuilder(url)
                {
                    Scheme = Uri.UriSchemeHttps,
                    Port = int.Parse(ConfigurationManager.AppSettings["httpsPort"])
                };
                url = uriBuilder.Uri.ToString();
            }

            return url;
        }

        public static AggregateFileSystemConfig GetAggregateFileSystemConfig()
        {
            var fi = new FileInfo(Assembly.GetEntryAssembly().Location);
            var aggFileSystemConfigPath = Path.Combine(fi.DirectoryName, "fs-config.json");
            var aggFileSystemConfig = AggregateFileSystemConfig.FromJsonPath(aggFileSystemConfigPath);

            return aggFileSystemConfig;
        }
    }
}
